script_enemy_main{

let angle1=rand(0,360);
let radius=0;
let angle2=rand(0,360);
let phase=0;

let character="Amaya";
let cutin=character;
let spellcards=9;
let spellcardnumber=49;
let dispelled=0;
let damagerate=10;
let outfit=5;
outfit=(128*outfit)-128;
let usespell=0;
let bgfade=0;
let frame=0;
let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SElaserm2=("script\SoundEffects\laserm2.wav");
let SEmagicb2=("script\SoundEffects\magicb2.wav");

let BG1=("\script\Images\BackgroundLayers\Witches1.png");
let BG2=("\script\Images\BackgroundLayers\Amaya1.png");
let GRboss=("\script\Images\CharacterSprites\Amaya.png");

#include_function "script/Functions/SetSpellcardCommonData.txt";
#include_function "script/Functions/SpellcardNameLoad.txt";
#include_function "script/Functions/HealthBarLoad.txt";
#include_function "script/Functions/CutInLoad.txt";

@Initialize{
	LoadUserShotData("script\shots\ShotsAmaya1.txt");

	LoadGraphic("\script\Images\BackgroundLayers\Witches1.png");
	LoadGraphic("\script\Images\BackgroundLayers\Amaya1.png");
	LoadGraphic("\script\Images\CharacterSprites\Amaya.png");

	LoadSE("script\SoundEffects\laserm2.wav");
	LoadSE("script\SoundEffects\magicb2.wav");

	SetScore(750000);
	SetLife(500);
	SetTimer(60);
	SetInvincibility(120);
	SetDamageRate(10,10);
	SetEnemyMarker(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	Focus(character);
	SetEffectForZeroLife(60,100,1);
	
	SetX(GetCommonData("Boss1X"));
	SetY(GetCommonData("Boss1Y"));
	SetMovePosition02(cx,miny+120,50);

	SetCommonData("Boss1Vanish",1);
}
	
@MainLoop{

SetCollisionA(GetX,GetY,16);
SetCollisionB(GetX,GetY,16);
SetShotAutoDeleteClip(32,128,32,32);

Weakness(character);
#include_function "script/Functions/Weakness.txt";
if(GetCommonData("BombOn")==0){ damagerate=10; }
if(GetCommonData("BombOn")==1){ damagerate=2.5; }
SetDamageRate(damagerate*weaken,damagerate*weaken);

let difficulty="";
if(GetCommonDataDefault("Difficulty",2)==1){ difficulty="Easy"; }
if(GetCommonDataDefault("Difficulty",2)==2){ difficulty="Normal"; }
if(GetCommonDataDefault("Difficulty",2)==3){ difficulty="Hard"; }
if(GetCommonDataDefault("Difficulty",2)==4){ difficulty="Lunatic"; }

SpellcardName("[Full Thunder Moon]",spellcardnumber); 
HealthBar();
Portrait(cutin,2);

if(frame==240){
	if(GetPlayerX>minx+50 && GetPlayerX<maxx-50){
	SetMovePosition01(GetPlayerX+rand(-30,30),rand(miny+100,miny+140),0.5);
	}
	if(GetPlayerX<=minx+50){
	SetMovePosition01(GetPlayerX+rand(15,30),rand(miny+100,miny+140),0.5);
	}
	if(GetPlayerX>=maxx-50){
	SetMovePosition01(GetPlayerX-rand(15,30),rand(miny+100,miny+140),0.5);
	}
}



if(frame==60){
let speed1=4;
loop(3){
let shot1=0;
let shot2=1;
	loop(10){
	let speed2=1.5;
	CreateShotA(shot1,GetX,GetY-50,0);
	SetShotDataA(shot1,0,speed1,angle1,2,-0.05,0,26);
	SetShotDataA(shot1,80,0,NULL,0,0.02,speed2,26);
	let delay=80;
		loop(6){
		speed2-=0.15;
		CreateShotA(shot2,0,0,15);
		SetShotDataA(shot2,0,0,angle1+160+rand(-4,4),0,0.02,speed2,14);
		AddShot(delay,shot1,shot2,0);
		delay+=0;
		}
	FireShot(shot1);
	angle1+=360/10;
	}
angle1+=360/30;
	loop(10){
	let speed2=1.5;
	let randangle=rand(-15,15);
	CreateShotA(shot1,GetX,GetY-50,0);
	SetShotDataA(shot1,0,speed1,angle1,2,-0.05,0,28);
	SetShotDataA(shot1,80,0,NULL,0,0.02,speed2,28);
	let delay=80;
		loop(6){
		speed2-=0.15;
		CreateShotA(shot2,0,0,15);
		SetShotDataA(shot2,0,0,angle1+160+rand(-4,4),0,0.02,speed2,16);
		AddShot(delay,shot1,shot2,0);
		delay+=0;
		}
	FireShot(shot1);
	angle1+=360/10;
	}
speed1-=0.8;
}
usespell=-40;
PlaySE(SEmagicb2);
}

if(frame>=120 && frame<240){
	if((phase+0)%2==0){
		loop(3){
		CreateLaser01(GetX+radius*cos(angle2),(GetY-50)+radius*sin(angle2),rand(4,5),angle2+90,rand_int(70,120),10,195,20);
		CreateLaser01(GetX+(180-radius)*cos(angle2),(GetY-50)+(180-radius)*sin(angle2),rand(4,5),angle2-90,rand_int(70,120),10,203,20);
		angle2+=360/3;
		}
	radius+=1.5;
	angle2+=33;
	}
	if((phase+1)%2==0){
		loop(3){
		CreateLaser01(GetX+(180-radius)*cos(angle2),(GetY-50)+(180-radius)*sin(angle2),rand(4,5),angle2+90,rand_int(70,120),10,195,20);
		CreateLaser01(GetX+radius*cos(angle2),(GetY-50)+radius*sin(angle2),rand(4,5),angle2-90,rand_int(70,120),10,203,20);
		angle2+=360/3;
		}
	radius+=1.5;
	angle2-=33;
	}
if(time%4==0){ PlaySE(SElaserm2); }
}

if(frame==240){ frame=0; radius=0; phase+=1; }


time++; frame++;
if(usespell>0){ usespell--; } if(usespell<0){ usespell++; }
SetCommonData("Boss1X",GetX); SetCommonData("Boss1Y",GetY);

#include_function "script/Functions/SpellcardName.txt";
#include_function "script/Functions/HealthBar.txt";
#include_function "script/Functions/CutIn.txt";

if(GetLife==0 && dispelled==0){ CreateEnemyFromFile("script\Functions\dispel.txt",GetX,GetY,0,0,character); dispelled=1; }
}

@BackGround{
	if(bgfade<255){ bgfade+=5; }

	SetGraphicRect(0,0,512,512);
	SetGraphicScale(1,1);
	SetTexture(BG1);
	SetAlpha(bgfade);
	SetColor(255,255,255);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,time/7);
	DrawGraphic(cx,cy);

	SetGraphicRect(0,0,300,300);
	SetGraphicScale(1.5,1.5);
	SetTexture(BG2);
	SetAlpha(bgfade);
	SetColor(255,255,255);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,0);
	DrawGraphic(cx,cy-100);
}

@DrawLoop{
	SetGraphicScale(1,1);
	SetTexture(GRboss);
	SetGraphicAngle(0,0,0);
	SetColor(255,255,255);
	SetRenderState(ALPHA);

	if(usespell>=1){ SetGraphicRect(384,outfit,512,outfit+128); }
	if(usespell<=-1){ SetGraphicRect(512,outfit,640,outfit+128); }
	if(usespell==0){
		if(GetSpeedX<=0.5 && GetSpeedX>=-0.5){ SetGraphicRect(0,outfit,128,outfit+128); }
		else if(GetSpeedX<-0.5){ SetGraphicRect(128,outfit,256,outfit+128); }
		else if(GetSpeedX>0.5){ SetGraphicRect(256,outfit,384,outfit+128); }
	}
	DrawGraphic(GetX,GetY);
}

@Finalize{
//	SetCommonData("Conversation",1);
	NewPointData(spellcardnumber,5);
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
}

}